package cn.com.shopec.erp.purchase.dao.impl;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.transform.Transformers;
import org.hibernate.type.StandardBasicTypes;
import org.springframework.stereotype.Repository;

import cn.com.shopec.erp.common.orm.impl.HibernateEntityDao;
import cn.com.shopec.erp.common.page.PageFinder;
import cn.com.shopec.erp.common.page.PageQuery;
import cn.com.shopec.erp.common.utils.LogicUtil;
import cn.com.shopec.erp.purchase.dao.IPurchaseReturnOrderDao;
import cn.com.shopec.erp.purchase.entity.PurchaseReturnOrder;
import cn.com.shopec.erp.purchase.vo.PurchaseRequisitionProductVo;
import cn.com.shopec.erp.purchase.vo.PurchaseReturnOrderVo;
import cn.com.shopec.erp.stock.vo.StockInVo;

/** 
 * @ClassName: PurchaseOrderDaoImpl 
 * @Description: 采购单表的dao实现
 * @author: lule
 * @date 2013-5-22 上午10:52:14
 *  
 */
@Repository
public class PurchaseReturnOrderDaoImpl extends HibernateEntityDao<PurchaseReturnOrder> implements IPurchaseReturnOrderDao {

	/**
	 * 根据采购单和货品单号查询数据
	 */
	@Override
	public PurchaseReturnOrder getPuNoByPurchaseRequest(String puNo, String prodNo) {
		if((!puNo.equals("") && puNo!=null) || !prodNo.equals("") && prodNo!=null){
				StringBuffer sql = new StringBuffer();
				sql.append("select t.id as id,"
						+ "t.puNo as puNo,"
						+ "t.poNo as poNo,"
						+ "t.prodNo as prodNo,"
						+ "t.commodityName as commodityName,"
						+ "t.specification as specification,"
						+ "t.supCode as supCode,"
						+ "t.supName as supName,"
						+ "t.purWhNo as purWhNo,"
						+ "t.purWhName as purWhName,"
						+ "t.returnQuantity as returnQuantity,"
						+ "t.totalPrice as totalPrice,"
						+ "t.purUnitPrice as purUnitPrice,"
						+ "t.returnDesc as returnDesc,"
						+ "t.creater as creater,"
						+ "t.createTime as createTime,"
						+ "t.updateTime as updateTime,"
						+ "t.status as status,"
						+ "t.auditResult as auditResult,"
						+ "t.curAuditPoint as curAuditPoint,"
						+ "t.lastAuditTime as lastAuditTime,"
						+ "t.lastAuditPerson as lastAuditPerson,"
						+ "t.description as description,"
						+ "t.remark as remark,"
						+ "t.deleteFlag as deleteFlag,"
						+ "t.is_settled as isSettled,"
						+ "t.yieldAmountNumner as yieldAmountNumner,"
						+ "t.defectiveAmountNumber as defectiveAmountNumber,"
						+ "t.commoNo as commoNo,"
						+ "t.prodBarCode as prodBarCode,"
						+ "t.prId as prId,"
						+ "t.purType as purType from "
						+ "TBL_PURCHASE_RETURN_ORDER t "
						+ "where t.puNo = '"+puNo+"' and t.prodNo = '"+prodNo+"' and deleteFlag = 1 ");
				Query query= getSession().createSQLQuery(sql.toString())
						.addScalar("id",StandardBasicTypes.STRING)
						.addScalar("puNo",StandardBasicTypes.STRING)
						.addScalar("poNo",StandardBasicTypes.STRING)
						.addScalar("prodNo",StandardBasicTypes.STRING)
						.addScalar("commodityName",StandardBasicTypes.STRING)
						.addScalar("specification",StandardBasicTypes.STRING)
						.addScalar("supCode",StandardBasicTypes.STRING)
						.addScalar("supName",StandardBasicTypes.STRING)
						.addScalar("purWhNo",StandardBasicTypes.STRING)
						.addScalar("purWhName",StandardBasicTypes.STRING)
						.addScalar("returnQuantity",StandardBasicTypes.INTEGER)
						.addScalar("totalPrice",StandardBasicTypes.STRING)
						.addScalar("purUnitPrice",StandardBasicTypes.STRING)
						.addScalar("returnDesc",StandardBasicTypes.STRING)
						.addScalar("creater",StandardBasicTypes.STRING)
						.addScalar("createTime",StandardBasicTypes.STRING)
						.addScalar("updateTime",StandardBasicTypes.STRING)
						.addScalar("status",StandardBasicTypes.INTEGER)
						.addScalar("auditResult",StandardBasicTypes.INTEGER)
						.addScalar("curAuditPoint",StandardBasicTypes.INTEGER)
						.addScalar("lastAuditTime",StandardBasicTypes.STRING)
						.addScalar("lastAuditPerson",StandardBasicTypes.STRING)
						.addScalar("description",StandardBasicTypes.STRING)
						.addScalar("remark",StandardBasicTypes.STRING)
						.addScalar("deleteFlag",StandardBasicTypes.INTEGER)
						.addScalar("isSettled",StandardBasicTypes.INTEGER)
						.addScalar("yieldAmountNumner",StandardBasicTypes.LONG)
						.addScalar("defectiveAmountNumber",StandardBasicTypes.LONG)
						.addScalar("commoNo",StandardBasicTypes.STRING)
						.addScalar("prodBarCode",StandardBasicTypes.STRING)
						.addScalar("prId",StandardBasicTypes.STRING)
						.addScalar("purType",StandardBasicTypes.INTEGER);
				query.setResultTransformer(Transformers.aliasToBean(PurchaseReturnOrder.class));
				PurchaseReturnOrder purchase = (PurchaseReturnOrder) query.uniqueResult();
				return purchase;
		}
		return null;
	}

	


	/**
     * 
     * @Title: updateBrand
     * @Description: 查询所有采购单退货
     * @param brandVo
     * @return
     * @throws
     * @author: duhui
     * @date: 2013-5-26下午04:17:40
     */
	/*@Override
	public PurchaseReturnOrderVo getPagedPurchaseOrderList(PurchaseRequisitionProductVo purchase) {
		
			String sql = "SELECT"
					+ " S.ID AS id,"
					+ " S.STOCKIN_NO AS stockInNo,"
					+ " S.STOCKIN_TYPE AS stockInType,"
					+ " S.STOCKIN_STATE AS stockInState,"
					+ " S.STOCKIN_TYPE_NO AS stockInTypeNo,"
					+ " S.WH_NO AS whNo,"
					+ " S.PUR_NO AS purNo,"
					+ " S.SUP_NO AS supNo,"
					+ " TW.WH_NAME AS whName,"
					+ " TSI.SUP_NAME AS supName,"
					+ " TPO.PONAME AS purName"
					+ " FROM TBL_STOCKIN S"
					+ " LEFT JOIN TBL_WAREHOUSE TW ON TW.WH_NO = S.WH_NO"
					+ " LEFT JOIN TBL_SUPPLIER_INFO TSI ON TSI.CODE = S.SUP_NO"
					+ " LEFT JOIN TBL_PURCHASE_ORDER TPO ON TPO.PO_NO = S.PUR_NO"
					+ " WHERE S.STOCKIN_NO = ?";
			Query query= getSession().createSQLQuery(sql)
					.addScalar("id",StandardBasicTypes.STRING)
					.addScalar("stockInNo",StandardBasicTypes.STRING)
					.addScalar("stockInTypeNo",StandardBasicTypes.STRING)
					.addScalar("whNo",StandardBasicTypes.STRING)
					.addScalar("purNo",StandardBasicTypes.STRING)
					.addScalar("supNo",StandardBasicTypes.STRING)
					.addScalar("whName",StandardBasicTypes.STRING)
					.addScalar("supName",StandardBasicTypes.STRING)
					.addScalar("purName",StandardBasicTypes.STRING)
					.addScalar("stockInType",StandardBasicTypes.INTEGER)
					.addScalar("stockInState",StandardBasicTypes.INTEGER);
			query.setParameter(0, stockNo).setResultTransformer(Transformers.aliasToBean(StockInVo.class));
			StockInVo stockInVo = (StockInVo) query.uniqueResult();
	}*/

}
